import Vue from 'vue'
import Vuex from 'vuex'
// const SET_TODOS = 'SET_TODOS'
import todolist from './todolist.module'
import girls from './girls.module'

Vue.use(Vuex)

const store = new Vuex.Store({
  // data
  state: {
    num: 100,
    list: [
      {text: 'title 1', id: 2345678},
      {text: 'title 2', id: 12312},
      {text: 'title 3', id: 5678},
      {text: 'title 4', id: 3456},
    ],
  },
  // computed
  getters: {
    numPI: state => state.num * Math.PI
  },
  // $store.commit()
  mutations: {
    increment (state) {
      state.num++
    },
    jian (state, data) {
      state.num -= data
    },
    createItem (state, data) {
      state.list.push(data)
    }
  },
  // $store.dispatch()
  actions: {
    createItemAction({ commit }, data) {
      commit('createItem', data)
    },
    addNum({ commit, state }) {
      // ajax
      // 'page=1?count=10'
      console.log(state.list)
      commit('increment')
    }
  },
  modules: {
    todolist,
    girls
  }
})

export default store


